#静默安装Oracle19数据库
#参考教程:
#https://blog.csdn.net/haopeng7816/article/details/83956623
#安装依赖
shell_Oracle_install_base_service(){
    Oracle_srv='binutils compat-libcap1 compat-libstdc++-33 
    compat-libstdc++-33*.i686 glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh 
    libaio libaio*.i686 libaio-devel libaio-devel*.i686 libX11 libX11*.i686 libXau 
    libXau*.i686 libXi libXi*.i686 libXtst libXtst*.i686 libgcc libgcc*.i686 libstdc++ 
    libstdc++*.i686 libstdc++-devel libstdc++-devel*.i686  libxcb libxcb*.i686 make nfs-utils 
    net-tools smartmontools sysstat unixODBC unixODBC-devel gcc gcc-c++ libXext libXext*.i686 
    zlib-devel zlib-devel*.i686 unzip'
    service_install $Oracle_srv
    init_srv='y'
}
shell_Oracle_install_config(){
    input "请设置当前主机名,默认[ `hostname` ]" host_name
    input_check "$host_name" "设置当前主机名" "[ `hostname` ]" "host_name"

    input "请设置用户[ oracle ]密码,默认: [ zgj123 ]" oracle_pass
    input_check "$oracle_pass" "设置用户[ oracle ]密码" "zgj123" oracle_pass

    input "请设置用户[ grid ]密码,默认: [ zgj123 ]" grid_pass
    input_check "$grid_pass" "设置用户[ grid ]密码" "zgj123" grid_pass
}
group_add(){
    /usr/sbin/groupadd -g 50001 oinstall
    /usr/sbin/groupadd -g 50002 dba
    /usr/sbin/groupadd -g 50003 oper
    /usr/sbin/groupadd -g 50004 backupdba
    /usr/sbin/groupadd -g 50005 dgdba
    /usr/sbin/groupadd -g 50006 kmdba
    /usr/sbin/groupadd -g 50007 asmdba
    /usr/sbin/groupadd -g 50008 asmoper
    /usr/sbin/groupadd -g 50009 asmadmin
    /usr/sbin/groupadd -g 50010 racdba
    /usr/sbin/useradd -u 50011 -g oinstall -G dba,asmdba,asmoper,asmadmin,racdba grid
    /usr/sbin/useradd -u 50012 -g oinstall -G dba,oper,backupdba,dgdba,kmdba,asmdba,racdba oracle
    echo "$oracle_pass" | passwd --stdin oracle
    echo "$grid_pass" | passwd --stdin grid
}
config_profile(){
    echo "export ORACLE_BASE=/opt/oracle/dbbase
export ORACLE_HOME=\$ORACLE_BASE/19c/db_1
export ORACLE_SID=emrep
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$ORACLE_HOME/oracm/lib
export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
umask 0022
# export DISPLAY=0.0.0.0:0.0
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LC_ALL=en_US.UTF-8" >> /home/oracle/.bash_profile
echo "export ORACLE_BASE=/opt/oracle/gbase
export ORACLE_HOME=/opt/oracle/ghome
export GI_HOME=\$ORACLE_HOME
export PATH=\$ORACLE_HOME/bin:\$PATH
export ORACLE_SID=+ASM1
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$ORACLE_HOME/oracm/lib
export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
umask 0022
# export DISPLAY=0.0.0.0:0.0
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LC_ALL=en_US.UTF-8" >> /home/grid/.bash_profile
}
config_os_var(){
    echo "NOZEROCONF=yes"  > /etc/sysconfig/network
    echo "grid  soft  nproc   16384
grid  hard  nproc   65536
grid  soft  nofile  32768
grid  hard  nofile  65536
grid  soft  stack   32768
grid  hard  stack   65536
grid  soft  memlock  -1
grid  hard  memlock  -1
oracle  soft  nproc   16384
oracle  hard  nproc   65536
oracle  soft  nofile  32768
oracle  hard  nofile  65536
oracle  soft  stack   32768
oracle  hard  stack   65536
oracle  soft  memlock  -1
oracle  hard  memlock  -1" > /etc/security/limits.conf
    echo "session required pam_limits.so" >> /etc/pam.d/login
    disable_firealld  #关闭防火墙
    echo "####fs setting
fs.aio-max-nr = 4194304
fs.file-max = 6815744
####kernel setting
kernel.shmall = 4194304
kernel.shmmax = 16106127360
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
kernel.panic_on_oops = 1
kernel.panic = 10
#### Net Setting
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 4194304
##TCP Cache Setting
net.ipv4.tcp_moderate_rcvbuf=1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.conf.ens36.rp_filter = 2
net.ipv4.conf.ens35.rp_filter = 2
net.ipv4.conf.ens34.rp_filter = 1
####Memory Setting
vm.vfs_cache_pressure=200 
vm.swappiness=10
vm.min_free_kbytes=102400
#vm.nr_hugepages=10" > /etc/sysctl.conf
    sysctl --system
}
shell_Oracle_install_all(){
    shell_Oracle_install_config
    if [[ "$init_srv" == 'y' ]];then
        green_zt "已安装基础环境"
    else
        shell_Oracle_install_base_service
    fi
    group_add
    config_profile
    config_os_var
}